package com.lucenly.card.adapter;

import android.content.Intent;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.lucenly.card.R;
import com.lucenly.card.activity.WebViewActivity;
import com.lucenly.card.bean.MsgBean;
import com.lucenly.card.utils.TimeUtils;

public class MsgAdapter extends BaseQuickAdapter<MsgBean,BaseViewHolder>{
    private String path="";

    public void setPath(String path) {
        this.path = path;
    }

    public MsgAdapter(){
        super(R.layout.item_msg);
    }
    @Override
    protected void convert(BaseViewHolder helper, final MsgBean item) {
        ImageView iv_img = helper.getView(R.id.iv_img);
        TextView tv_title = helper.getView(R.id.tv_title);
        TextView tv_content = helper.getView(R.id.tv_content);
        LinearLayout ll_item = helper.getView(R.id.ll_item);
        TextView tv_time = helper.getView(R.id.tv_time);
        if(item.typeId==1){
           iv_img.setBackgroundResource(R.mipmap.notify);
        }else{
            iv_img.setBackgroundResource(R.mipmap.msg);
        }
        tv_title.setText(item.title);
        tv_content.setText(item.content);
        tv_time.setText(TimeUtils.stampToDate(item.createTime*1000+"","yyyy-MM-dd"));
        ll_item.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                if(item.typeId==2){
                    Intent intent = new Intent(mContext, WebViewActivity.class);
                    intent.putExtra("path",path+item.id);
                    mContext.startActivity(intent);
                }
            }
        });
    }
}
